# CFLAGS = -march=native -fno-strict-aliasing -g
# CFLAGS = -march=native -fno-strict-aliasing -O2
CFLAGS = -march=native -fno-strict-aliasing -O3
CC = gcc
TILE_SHAPE ?= 256

CFLAGS += -DTILE_SHAPE=$(TILE_SHAPE)  # 16x16 or 8x8
CFLAGS += -DENABLE_TRACE=$(ENABLE_TRACE)
CFLAGS += -DL2_LOOP=$(L2_LOOP)

# Directories
SRC_DIR = .
BUILD_DIR = ../build
BIN_DIR = ../bin
INCLUDE_DIR = ../include

BIN = $(BIN_DIR)/benchamx.out
ASS = $(BUILD_DIR)/benchamx.s
SRCS = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/amx/*.c) $(wildcard $(SRC_DIR)/vnni_avx512/*.c)
OBJS = $(patsubst %.c, $(BUILD_DIR)/%.o, $(notdir $(SRCS)))
HDRS = $(wildcard $(INCLUDE_DIR)/*.h)

default: all

print:
	@echo $(OBJS)

all: build $(BIN)

build:
	mkdir -p $(BUILD_DIR)	

$(BIN): $(OBJS)
	mkdir -p $(BIN_DIR)
	$(CC) $(CFLAGS) -I$(INCLUDE_DIR) -o $@ $^

$(BUILD_DIR)/%.o: %.c
	$(CC) $(CFLAGS) -I$(INCLUDE_DIR) -c $<  -o $@

$(BUILD_DIR)/%.o: $(SRC_DIR)/amx/%.c
	$(CC) $(CFLAGS) -I$(INCLUDE_DIR) -c $<  -o $@

$(BUILD_DIR)/%.o: $(SRC_DIR)/vnni_avx512/%.c
	$(CC) $(CFLAGS) -I$(INCLUDE_DIR) -c $<  -o $@

ass:
	mkdir -p $(BUILD_DIR)
	$(CC) $(CFLAGS) $(SRC_DIR)/amx/amx_l2.c -I$(INCLUDE_DIR) -o $(ASS) -S

clean:
	rm -rf $(BUILD_DIR) $(BIN_DIR)

.PHONY:  all build clean test ass
